package com.csun.cmny.python;

import org.python.antlr.ast.Str;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-03-19 11:33
 * @Description:
 */
public class InvokeByRuntime {

    /**
     * @param args
     * @throws IOException
     * @throws InterruptedException
     */
    public static void main(String[] args) throws IOException, InterruptedException {
//        String exe = "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\python.exe";
//        String command = "D:\\calculator_simple.py";
//        String num1 = "1";
//        String num2 = "2";
//        String[] cmdArr = new String[] {exe, command, num1, num2};
//        Process process = Runtime.getRuntime().exec(cmdArr);
//        InputStream is = process.getInputStream();
//        DataInputStream dis = new DataInputStream(is);
//        String str = dis.readLine();
//        process.waitFor();
//        System.out.println(str);

        String exe = "C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\python.exe";
        String command = "G:\\python\\20190322-2signal_interp.py";
        String agrs = "input.json";
        String t_type = "-t";
        String datatime = "-100,-90,-75,-60,-50,-30,-20,-5,0";
        String r_type = "-r";
        String signal = "-r 33,34,36,36,35,33,36,35,33,38,40";
        String b_type = "-b";
        String start = "-210";
        String e_type = "-2";
        String end = "0";
        String s_type = "-s";
        String step = "5";
//        String[] cmdArr = new String[] {exe, command, t_type, datatime, r_type, signal, b_type, start, e_type, end, s_type, step};
        String[] cmdArr = new String[] {exe, command, "-t-215,-190,-180,-150,-140,-130,-90,-60,-50,-20,0 -r 33,34,36,36,35,33,36,35,33,38,40 -b -210 -e 0 -s 5"};
//        Process process = Runtime.getRuntime().exec("C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\python.exe D:\\signal_interp.py -t-215,-190,-180,-150,-140,-130,-90,-60,-50,-20,0 -r 33,34,36,36,35,33,36,35,33,38,40 -b -210 -e 0 -s 5");
//        Process process = Runtime.getRuntime().exec("C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\python.exe D:\\calculator_simple.py 1 2");
//        Process process = Runtime.getRuntime().exec("C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\python.exe D:\\test.py");

        String[] args1 = new String[]{exe, command, agrs};

        Process process = Runtime.getRuntime().exec(args1);
        InputStream is = process.getInputStream();
        DataInputStream dis = new DataInputStream(is);
        String str = dis.readLine();
        process.waitFor();
        System.out.println(str);
    }

}
